import service from "@/api/service";

export default {
  namespaced: true,
  state: {
    functions: null,
    types: [
      {
        value: "System.Boolean",
        label: "Boolean",
      },
      {
        value: "System.Char",
        label: "Char",
      },
      {
        value: "System.SByte",
        label: "SByte",
      },
      {
        value: "System.Byte",
        label: "Byte",
      },
      {
        value: "System.Int16",
        label: "Int16",
      },
      {
        value: "System.UInt16",
        label: "UInt16",
      },
      {
        value: "System.Int32",
        label: "Int32",
      },
      {
        value: "System.UInt32",
        label: "UInt32",
      },
      {
        value: "System.Int64",
        label: "Int64",
      },
      {
        value: "System.UInt64",
        label: "UInt64",
      },
      {
        value: "System.Single",
        label: "Single",
      },
      {
        value: "System.Double",
        label: "Double",
      },
      {
        value: "System.Decimal",
        label: "Decimal",
      },
      {
        value: "System.DateTime",
        label: "DateTime",
      },
      {
        value: "System.DateTimeOffset",
        label: "DateTimeOffset",
      },
      {
        value: "System.String",
        label: "String",
      },
    ],
  },
  mutations: {
    FUNCTIONS(state, functions) {
      state.functions = functions;
    },
  },
  actions: {
    scriptFunctions({ commit, state }) {
      return new Promise((resolve, reject) => {
        service.scripting
          .functions()
          .then((response) => {
            commit("FUNCTIONS", response.success ? response.data : null);
            resolve(response);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
  },
};
